package com.example.capsule.dto;

import com.example.capsule.entity.Capsule;
import java.time.LocalDateTime;

/**
 * 时光胶囊响应DTO
 */
public class CapsuleResponse {

    private Long id;
    private String title;
    private String content;
    private String imageUrl;
    private LocalDateTime unlockTime;
    private LocalDateTime createdAt;
    private Boolean isUnlocked;
    private Boolean isPublic;


    // 构造方法
    public CapsuleResponse() {}

    public CapsuleResponse(Capsule capsule, String baseUrl) {
        this.id = capsule.getId();
        this.title = capsule.getTitle();
        this.content = capsule.getContent();
        this.unlockTime = capsule.getUnlockTime();
        this.createdAt = capsule.getCreatedAt();
        this.isUnlocked = capsule.getIsUnlocked();
        this.isPublic=capsule.getIsPublic();
        // 修复：构建完整的图片URL
        if (capsule.getImagePath() != null && !capsule.getImagePath().isEmpty()) {
            String imagePath = capsule.getImagePath();
            if (imagePath.startsWith("/")) {
                imagePath = imagePath.substring(1);
            }
            this.imageUrl = baseUrl + "/upload/" + imagePath;
        } else {
            this.imageUrl = null;
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public LocalDateTime getUnlockTime() {
        return unlockTime;
    }

    public void setUnlockTime(LocalDateTime unlockTime) {
        this.unlockTime = unlockTime;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public Boolean getUnlocked() {
        return isUnlocked;
    }

    public void setUnlocked(Boolean unlocked) {
        isUnlocked = unlocked;
    }

    public Boolean getPublic() {
        return isPublic;
    }

    public void setPublic(Boolean aPublic) {
        isPublic = aPublic;
    }
}